/* 文章分类模块
 * @Author: Leil 
 * @Date: 2018-08-23 10:54:11 
 * @Last Modified by: Leil
 * @Last Modified time: 2018-08-24 01:06:57
 */
const Category = require('../lib/mongo').Category

function addOneCategory(data) {
    return Category
        .insertOne(data)
        .exec()
}

function getCategories() {
    return Category
        .find()
        .sort({sort: 1})
        .exec()
}

function delCategoryById(categoryId) {
    return Category
        .deleteOne({_id: categoryId})
        .exec()
}

function getCategoryById(categoryId) {
    return Category
        .findOne({_id: categoryId})
        .exec()
}

function updateCategoryById(categoryId, data) {
    return Category
        .updateOne({_id: categoryId}, {$set: data})
        .exec()
}


module.exports = {
    addOneCategory,
    getCategories,
    delCategoryById,
    getCategoryById,
    updateCategoryById
}